//
//  ZZCSettingViewCell.m
//  B段项目
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCSettingViewCell.h"

@implementation ZZCSettingViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createSubView];
    }
    return self;
}



-(void)createSubView{
    
//    //类型
//    self.type = [[UILabel alloc]init];
//    self.type.font = [UIFont systemFontOfSize:WIDTH/25];
//    self.type.textColor = [UIColor colorWithRed:0.47 green:0.47 blue:0.47 alpha:1];
//    [self.contentView addSubview:self.type];
//    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
//       
//        make.top.left.mas_equalTo(WIDTH / 20);
//        make.width.mas_equalTo(150);
//        make.height.mas_equalTo(WIDTH / 25);
//    }];
//    
//    
//    self.titleLb = [[UILabel alloc]init];
//    self.titleLb.font = [UIFont boldSystemFontOfSize:WIDTH/20];
//    self.titleLb.numberOfLines = 0;
//    [self.contentView addSubview:self.titleLb];
//    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.mas_equalTo(WIDTH / 20);
//        make.top.equalTo(self.type.mas_bottom).offset(WIDTH / 10);
//        make.width.mas_equalTo(WIDTH * 0.9);
//        make.height.mas_equalTo(WIDTH / 20);
//    }];
//    
//    
//    self.imgView = [[UIImageView alloc]init];
//    self.imgView.contentMode = UIViewContentModeScaleAspectFill;
//    self.imgView.clipsToBounds = YES;
//    [self.contentView addSubview:self.imgView];
//    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.mas_equalTo(WIDTH / 20);
//        make.top.equalTo(self.titleLb.mas_bottom).offset(WIDTH / 20);
//        make.width.mas_equalTo(WIDTH * 0.9);
//        make.height.mas_equalTo(HEIGHT / 4);
//    }];
    
    //类型
    self.type = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/20,WIDTH/20, 150, WIDTH/25)];
    self.type.font = [UIFont systemFontOfSize:WIDTH/25];
    self.type.textColor = [UIColor colorWithRed:0.47 green:0.47 blue:0.47 alpha:1];
    [self.contentView addSubview:self.type];
    
    
    self.titleLb = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/20, self.type.frame.origin.y * 2 + self.type.frame.size.height, WIDTH - WIDTH/10, WIDTH/20)];
    self.titleLb.font = [UIFont boldSystemFontOfSize:WIDTH/20];
    self.titleLb.numberOfLines = 0;
    [self.contentView addSubview:self.titleLb];
    
    
    
    self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/20, WIDTH/20 + self.titleLb.frame.size.height + self.titleLb.frame.origin.y, WIDTH - WIDTH/10, HEIGHT/4)];
    
    self.imgView.contentMode = UIViewContentModeScaleAspectFill;
    self.imgView.clipsToBounds = YES;
    [self.contentView addSubview:self.imgView];

    
}


#pragma mark - set
-(void)setMyModel:(HLJHomeModel *)myModel{
    
    _myModel = myModel;
    
    self.type.text = self.myModel.name;
    self.titleLb.text = self.myModel.title;
    [self.imgView sd_setImageWithURL:self.myModel.coverimg placeholderImage:PLACEHOLDER_IMAGE];
    //重新设置title frame
    CGFloat titleHeight = [ZZCSettingViewCell heightForTitle:self.myModel.title];
    CGRect tepFrame = self.titleLb.frame;
    tepFrame.size.height = titleHeight;
    self.titleLb.frame = tepFrame;
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(WIDTH / 20);
        make.top.equalTo(self.titleLb.mas_bottom).offset(WIDTH / 20);
        make.width.mas_equalTo(WIDTH * 0.9);
        make.height.mas_equalTo(HEIGHT / 4);
    }];
}



#pragma mark - 标题高度方法
+(CGFloat)heightForTitle:(NSString *) title{
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:WIDTH/20],NSFontAttributeName, nil];
    
    CGSize size = CGSizeMake(WIDTH - WIDTH/10, 10000);
    
    CGRect frame = [title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
